home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1999 November / SOTMC_Nov1999-Ultimate.iso / mac / REALbasic ƒ / Examples / Techniques / Examples by Thomas Tempelmann / TT's HideMenubar-Plugin / Source Code (CW Pro 3) / Some Libs & Stubs / MenusLib Interface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-06  |  2.5 KB  |  95 lines  |  [TEXT/CWIE]

  1. /*
  2.  * MenusLib Interface.c
  3.  *
  4.  * calls PPC routines in "MenusLib Stub.c"
  5.  *
  6.  * You ask why do we need that Stub?
  7.  * Well, for a PPC-only plugin, one could include the MenusLib
  8.  * and call the functions directly. However, that would require
  9.  * the MenusLib to be present even when it is not needed. Mac OS
  10.  * before 8.5 does not have the Lib installed and so you'd be
  11.  * getting an error when loading the plugin (and your app would
  12.  * kind of crash). By using this dynamically loadable stub,
  13.  * we decide whether we want to access the MenusLib at all and
  14.  * will make the plugin work with all OS versions.
  15.  * And, for a 68K plugin, there's no Trap provided for calling
  16.  * the new Menu Mgr functions, so we need this stub in order to
  17.  * switch into PowerPC mode and then call the functions.
  18.  *
  19.  * Updated 3 May, 99 for v1.1:
  20.  *   Fixed code so that it can also call the PPC stub if this code runs in PPC mode, too.
  21.  *
  22.  * Updated 6 May, 99 for v1.1.1:
  23.  *   Added DetachResource() call in getStub() so that built apps will not crash any more.
  24.  */
  25.  
  26. #include <MixedMode.h>
  27. #include "MenusLib Stub.h"
  28. #include "MenusLib Interface.h"
  29.  
  30.  
  31. static far MenusLibFuncs funcs = {0};
  32.  
  33. static far Boolean stubOK;
  34.  
  35. static MenusLibStubProc getStub ()
  36. {
  37.     Handle    resource;
  38.     resource = Get1Resource ('MLib', 128);
  39.     if (!resource) return nil;
  40.     DetachResource (resource);    // v1.1.1 - this is important or we'll get crashes in built apps
  41.     HLockHi (resource);
  42.     return (MenusLibStubProc)*resource;
  43. }
  44.  
  45. pascal void MenusLibShowMenuBar (void)
  46. {
  47.     if (stubOK) {
  48.         #if TARGET_RT_MAC_CFM
  49.             CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.showMenuBar, kPascalStackBased);
  50.         #else
  51.             funcs.showMenuBar();
  52.         #endif
  53.     }
  54. }
  55.  
  56. pascal void MenusLibHideMenuBar (void)
  57. {
  58.     if (stubOK) {
  59.         #if TARGET_RT_MAC_CFM
  60.             CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.hideMenuBar, kPascalStackBased);
  61.         #else
  62.             funcs.hideMenuBar();
  63.         #endif
  64.     }
  65. }
  66.  
  67. pascal Boolean MenusLibIsMenuBarVisible (void)
  68. {
  69.     if (stubOK) {
  70.         #if TARGET_RT_MAC_CFM
  71.             return CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.isMenuBarVisible, kPascalStackBased|RESULT_SIZE(SIZE_CODE(sizeof(Boolean))));
  72.         #else
  73.             return funcs.isMenuBarVisible();
  74.         #endif
  75.     } else {
  76.         return false;
  77.     }
  78. }
  79.  
  80. Boolean InitMenusLibInterface ()
  81. {
  82.     MenusLibStubProc initMenusLibStub = getStub();
  83.     stubOK = initMenusLibStub != nil;
  84.     if (stubOK) {
  85.         #if TARGET_RT_MAC_CFM
  86.             CALL_ONE_PARAMETER_UPP((UniversalProcPtr)initMenusLibStub, MenusStubInitProcInfo, &funcs);
  87.         #else
  88.             initMenusLibStub (&funcs);
  89.         #endif
  90.     }
  91.     return stubOK;
  92. }
  93.  
  94. // EOF
  95.